package com.epro.dx.task;

import java.util.ArrayList;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.epro.dx.util.ActivityUtil;
import com.epro.dx.util.OnekeyFilterLocalUtil;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.model.ModuleChildrenModel;
import com.weipu.common.facade.model.ProductModel;

import android.content.Context;
import android.os.AsyncTask;

/************************
 * @author Tony
 * @Date:2016-4-14下午5:19:09
 * @描述:获取活动对应产品列表
 ************************/
public class GetActivityProductListAsyncTask extends AsyncTask<Void,Void,String> {

	private MyAsyncTaskListenner myAsyncTaskListenner;
	private int pageIndex;
	private int pageSize;
	private ArrayList<ProductModel> productList;
	private String orderbyField;
	private Context mContext;
	private int activeType;
	private String activeID;
	public GetActivityProductListAsyncTask(Context mContext,int activeType,String activeID,int pageIndex,int pageSize,String orderbyField,MyAsyncTaskListenner myAsyncTaskListenner){
		this.mContext = mContext;
		this.activeType = activeType;
		this.activeID = activeID;
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.orderbyField = orderbyField;
		this.myAsyncTaskListenner = myAsyncTaskListenner;
	}
	@Override
	protected void onPreExecute() {
		if(null!=myAsyncTaskListenner){
			myAsyncTaskListenner.onPreTask();
		}
	}
	@Override
	protected String doInBackground(Void... params) {
		try {
			productList = ProviderFactory.createProductProvider().getActiveProduct(activeType, activeID, pageIndex, pageSize, orderbyField, 
					ActivityUtil.getCustomerID(), OnekeyFilterLocalUtil.getFilterState(mContext), OnekeyFilterLocalUtil.getLocalCategoryIds(mContext));
		} catch (DxException e) {
			return e.getErrCode();
		}
		return "0";
	}
	@Override
	protected void onPostExecute(String result) {
		if(null!=myAsyncTaskListenner){
			myAsyncTaskListenner.onPostTask(result, productList);
		}
	}

}
